<?php

namespace App\Models;

class UserLessonDub extends Model
{
    protected $table = 'user_lesson_dubs';


    public function scopeOfUserLesson($query, $userId, $lessonId)
    {
        return $query->where('user_id', $userId)->where('lesson_id', $lessonId);
    }

    public function scopeOfUserPage($query, $userId, $lessonId, $pageId)
    {
        return $query->where('user_id', $userId)->where('lesson_id', $lessonId)->where('page_id', $pageId);
    }



    public function setUserId($userId)
    {
        $this->user_id = $userId;
    }

    public function setLessonId($lessonId)
    {
        $this->lesson_id = $lessonId;
    }

    public function setPageId($pageId)
    {
        $this->page_id = $pageId;
    }

    public function setUri($url)
    {
        $this->uri = $url;
    }

    public function getUri()
    {
        return $this->uri;
    }

    public function setScore($score)
    {
        $this->score = $score;
    }

    public function setStar($star)
    {
        $this->star = $star;
    }

    public function getStar()
    {
        return $this->star;
    }

    public function getDuration()
    {
        return $this->duration;
    }

    public function setDuration($duration)
    {
        $this->duration = $duration;
    }

    public static function scoreToStar($score)
    {
        if ($score > 80) {
            return 3;
        } elseif ( $score > 40) {
            return 2;
        } elseif ($score > 10) {
            return 1;
        } else {
            return 0;
        }
    }
}
